package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbSpecialProcessVersion;
import com.sailfish.springbootdemo.pojo.db2.SfcRate;
import com.sailfish.springbootdemo.pojo.db2.SfsFile;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface SfsFileDao {
    @Results(id = "sfsFileResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "big_type", property = "bigType", jdbcType = JdbcType.INTEGER),
            @Result(column = "file_table_name", property = "fileTableName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "file_id", property = "fileId", jdbcType = JdbcType.INTEGER),
            @Result(column = "file_sid", property = "fileSid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "state", property = "state", jdbcType = JdbcType.VARCHAR),
            @Result(column = "preview_url", property = "previewUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "secret_key", property = "secretKey", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
    })

    /*
     *查询单个
     */
    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.SFS_FILE +
            " where id = #{id}" +
            "</script>")
    SfsFile getById(@Param("id") Integer id);

    /*
     *按条件查询
     */
    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.SFS_FILE +
            "<where>" +
            "<if test='bigType != null'>" +
            " and big_type = #{bigType}" +
            "</if>" +
            "<if test='fileTableName != null'>" +
            " and file_table_name = #{fileTableName}" +
            "</if>" +
            "<if test='fileId != null'>" +
            " and file_id = #{fileId}" +
            "</if>" +
            "</where>" +
            "</script>")
    List<SfsFile> getByLimit(SfsFile param);

    @Insert("insert into " + DB2TableName.SFS_FILE + "(big_type, file_table_name, file_id, file_sid, name, state, preview_url, secret_key, create_time, create_user) values" +
            " (#{bigType}, #{fileTableName}, #{fileId}, #{fileSid}, #{name}, #{state}, #{previewUrl}, #{secretKey}, #{createTime}, #{createUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insert(SfsFile param);

}
